<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script type="text/javascript">
      var train_task_id = <%=params[:train_task_id]%>       //从前面的链接得到id的值
      Ext.onReady(function(){

        var dateDateField = new Ext.form.DateField({
          fieldLabel: '日报日期',
          name: 'date',
          format: 'Y-m-d',                    //格式化日期
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "设备故障日期必须选择",
          emptyText: '请选择日期...',
          anchor: '90%'                    //在容器中的时候，自动按照容器百分比进行调整，会覆盖宽度的属性
        });

        var trainDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/train/getTrains'}),
          reader:new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'train'
          }, [
            {name:'sn'},                            //用作后面的displayField:
            {name:'id'}                                //用作后面的valueField:
          ])
        });
        var trainIdCombo = new Ext.form.ComboBox({  //配合上面的departmentDS，完成动态生成的下拉框
          store: trainDS,
          hiddenName:'train_id',            //显示时：这里写后台传送过来的字段，一旦和valueField相等，就进行显示。不相等为空。
          displayField:'sn',              //store里面的值，用于显示在表面上的值
          valueField:'id',                  //store里面的值，和display联动
          typeAhead: true,
          disable:true,
          minChars:1,
          readOnly:false,
          anchor: '90%',                    //在容器中的时候，自动按照容器百分比进行调整，会覆盖宽度的属性
          mode: 'remote',
          fieldLabel:'列车选择',
          forceSelection: true,
          triggerAction: 'all',
          emptyText:'请选择列车.....',
          selectOnFocus:true
        });

        var newDailyForm=new Ext.form.FormPanel({
          width:780,
          url:'/daily/create',
          labelAlign: 'top',
          buttonAlign:'center',
          fileUpload: true,
          autoHeight:true,
          bodyStyle: 'padding:5px',
          labelWidth:100,
          waitMsgTarget: true,
          frame: true,
          items:[
            {layout:'column'
              ,items:[
                {columnWidth:.5
                  ,layout:'form'
                  ,items:[{
                      xtype:'fieldset',
                      title:'日常走行',
                      buttonAlign: 'center',
                      autoHeight:true,
                      items:[
                        trainIdCombo,
                        dateDateField,
                        {
                          xtype:'textfield',
                          fieldLabel: '上次走行公里',
                          name: 'last_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'textfield',
                          fieldLabel: '本次走行公里',
                          name: 'now_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'textfield',
                          fieldLabel: '总走行公里数',
                          name: 'all_length',
                          readOnly:false,
                          anchor:'95%'
                        }
                      ]
                    }]
                }
                ,{columnWidth:.5
                  ,layout:'form'
                  ,items:[{
                      xtype:'fieldset',
                      title:'维修后走行',
                      buttonAlign: 'center',
                      autoHeight:true,
                      items:[{
                          xtype:'textfield',
                          fieldLabel: '镟修后公里数',
                          name: 'xx_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'textfield',
                          fieldLabel: '探伤后公里数',
                          name: 'ts_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'textfield',
                          fieldLabel: '三级修后公里',
                          name: 'threex_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'textfield',
                          fieldLabel: '四级修后公里',
                          name: 'fourx_length',
                          readOnly:false,
                          anchor:'95%'
                        }]
                    }]
                }
              ]
            }
          ],
          buttons:[{
              text:'确认保存',
              handler: function(){
                if (newDailyForm.form.isValid()) {
                  newDailyForm.form.submit({
                    method: 'post',
                    waitMsg: '正在创建日报...',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        newDailyWin.destroy();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                      Ext.MessageBox.alert('消息', response.result.info);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text:'取消',
              handler:function(){
                newDailyWin.destroy();
              }
            }]
        });
        newDailyForm.render('new_daily_form');
      });
    </script>
  </head>
  <body>
    <div id="new_daily_form"></div>
  </body>
</html>